import { Body, Controller, Get, Param, Patch, Post, Query } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger/dist/decorators';
import { LoginWxUserDto } from './dto/login-wxuser.dto';
import { RecudePhoneCountDto } from './dto/recude-phone-count-dto';
import { UpdateWxUserDto } from './dto/update-wxuser.dto';
import { WxuserService } from './wxuser.service';

@ApiTags('小程序用户')
@Controller('wxuser')
export class WxuserController {
  constructor(private readonly wxuserService: WxuserService) {}

  @Post('login')
  async wxUserLogin(@Body() dto: LoginWxUserDto) {
    console.log(dto);
    return await this.wxuserService.wxUserLogin(dto)
  }

  @Post(':id')
  async updateWxUser(@Param('id') id: string, @Body() dto: UpdateWxUserDto) {
    console.log(id, dto);
    
    return await this.wxuserService.updateWxUser(id, dto)
  }
  
  @Get('page')
  async findPage(@Query() query: any) {
    return await this.wxuserService.findPage(query)
  }

  @Post('addVip/:id')
  async addVip(@Param('id') id: string, @Body() dayDto: { id: string, day: number, discount: number, bonusCoins: number }) {
    return await this.wxuserService.addVip(id, dayDto)
  }

  @Post('addCoin/:id')
  async addCount(@Param('id') id: string, @Body() coinDto: { coin: number }) {
    return await this.wxuserService.addCoin(id, coinDto)
  }

  @Post('reduce/channel')
  async reducePhoneCountByChannel(@Body() dto: RecudePhoneCountDto) {
    return await this.wxuserService.reducePhoneCountByChannel(dto)
  }

  @Post('reduce/clue')
  async reducePhoneCountByClue(@Body() dto: RecudePhoneCountDto) {
    return await this.wxuserService.reducePhoneCountByClue(dto)
  }

  @Post('reduce/peer')
  async reducePhoneCountByPeer(@Body() dto: RecudePhoneCountDto) {
    return await this.wxuserService.reducePhoneCountByPeer(dto)
  }

  @Get('check/channel')
  async checkHaveChannel(@Query() query: {id: string, userId: string}) {
    return await this.wxuserService.checkHaveChannel(query.id, query.userId)
  }

  @Get('check/clue')
  async checkHaveClue(@Query() query: {id: string, userId: string}) {
    return await this.wxuserService.checkHaveClue(query.id, query.userId)
  }

  @Get('check/peer')
  async checkHavaPeer(@Query() query: {id: string, userId: string}) {
    return await this.wxuserService.checkHavePeer(query.id, query.userId)
  }

  @Get('myChannel')
  async getMyChannel(@Query() query: {id: string}) {
    return await this.wxuserService.getMyChannel(query.id)
  }

  @Get('myClue')
  async getMyClue(@Query() query: {id: string}) {
    return await this.wxuserService.getMyClue(query.id)
  }

  @Get('myPeer')
  async getMyPeer(@Query() query: { id: string }) {
    return await this.wxuserService.getMyPeer(query.id)
  }

  @Get('expire/:id')
  async checkWxUserExpire(@Param('id') id: string) {
    return await this.wxuserService.checkWxUserExpire(id)
  }

  @Get('detail/:id')
  async getUserDetail(@Param('id') id: string) {
    return await this.wxuserService.getUserDetail(id)
  }
}
